<%@ page import="util.DBUtil" %>
<%@ page import="java.sql.ResultSet" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2023/10/26
  Time: 15:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <h2>商品信息管理</h2>
    <a href="product_add.jsp">新增商品</a>

    <table>
        <tr>
            <td>分类</td><td>名称</td><td>简介</td>
            <td>价格</td> <td>销售价格</td> <td>logo</td>
            <td>状态</td> <td>是否置顶</td> <td>排序序号</td>
        </tr>

        <%
            String sql = " select tb_product.*, type_name"
                    +"   from tb_product,tb_product_type "
                    +"   where tb_product.type_id  = tb_product_type.id"
                    +"  order by is_top desc, idx asc";
            DBUtil  dbUtil  = new DBUtil();
            ResultSet rs = dbUtil.query(sql);
            while(rs.next()){
                out.print("<tr>");
                out.print("<td>"+rs.getString("type_name")+"</td>");
                out.print("<td>"+rs.getString("product_name")+"</td>");
                out.print("<td>"+rs.getString("intro")+"</td>");
                out.print("<td>"+rs.getString("price")+"</td>");
                out.print("<td>"+rs.getString("sale_price")+"</td>");
                out.print("<td>"+rs.getString("logo")+"</td>");
                String statusTitle="";
                switch (rs.getInt("status")){
                    case 1:statusTitle="上架";break;
                    case 0:statusTitle="下架";break;
                }
                out.print("<td>"+statusTitle+"</td>");
                out.print("<td>"+
                        (rs.getInt("is_top")==1?"是":"否") +"</td>");
                out.print("<td>"+rs.getString("idx")+"</td>");
                out.print("<td>"
                        +"<a href=\"product_edit.jsp?id="+rs.getInt("id")+"\">修改</a>"+"</td>");
                out.print("</tr>");
            }
        %>


    </table>
</body>
</html>
